package com.recipedb.recipedb.controller;

import com.recipedb.recipedb.entity.Tag;
import com.recipedb.recipedb.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Optional;

@RestController
@RequestMapping("/api/tag")
public class TagController {

    @Autowired
    private TagService service;

    @PostMapping
    public Tag add(@RequestBody Tag entity) {
        return service.save(entity);
    }

    @DeleteMapping
    public void delete(@RequestParam Long id) {
        service.deleteById(id);
    }

    @GetMapping("/single")
    public Optional<Tag> get(@RequestParam Long id) {
        return service.findById(id);
    }

    @GetMapping("/all")
    public List<Tag> getAll() {
        return service.findAll();
    }

    //小侯
    // 新增接口：通过食谱ID查询标签
    @GetMapping("/by-recipe")
    public List<Tag> getByRecipeId(@RequestParam Long recipeId) {
        return service.findByRecipeId(recipeId);
    }
    //小侯

}
